package com.example.myworkc;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnLoadMoreListener;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class weixinBlankFragment extends Fragment {
    private RecyclerView recyclerView;
    private Context context;
    private List<Map<String,Object>> items;
    private Myadapter myadapter;


    public weixinBlankFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.weixin_blank, container, false);
            context=this.getActivity();
            recyclerView=view.findViewById(R.id.recyclerview);
        String[] name={"甘雨","川普","辉夜","熊二"};
        String[] words={"原神中的一个人气角色","美国总统", "动漫辉夜大小姐的女主角","熊出没中的笨蛋"};
        int[] png={R.drawable.ganyu, R.drawable.d1,R.drawable.huiye, R.drawable.xionger};
        List<Map<String,Object>> items=new ArrayList<Map<String,Object>>();
        for(int i=0;i<name.length;i++) {
            Map<String,Object> item=new HashMap<String,Object>();
            item.put("name", name[i]);
            item.put("words", words[i]);
            item.put("png",png[i]);
            items.add(item);      }
        myadapter = new Myadapter(items,context);
        LinearLayoutManager layoutManager = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.addItemDecoration(new DividerItemDecoration(context,DividerItemDecoration.VERTICAL));//设置分割线
        recyclerView.setAdapter(myadapter);
        RefreshLayout refreshLayout = view.findViewById(R.id.refreshLayout);
        refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                refreshlayout.finishRefresh(200/*,false*/);//传入false表示刷新失败
                items.clear();
                String[] name={"李德敖"};
                String[] words={"少爷别玩了"};
                int[] png={R.drawable.lda};
                for(int i=0;i<name.length;i++) {
                    Map<String, Object> item = new HashMap<String, Object>();
                    item.put("name", name[i]);
                    item.put("words", words[i]);
                    item.put("png", png[i]);
                    items.add(item);
                }
                myadapter.notifyDataSetChanged();
            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(RefreshLayout refreshlayout) {
                refreshlayout.finishLoadMore(200/*,false*/);//传入false表示加载失败
                String[] name={"lda"};
                String[] words={"帅逼德奥"};
                int[] png={R.drawable.lxl};
                for(int i=0;i<name.length;i++) {
                    Map<String, Object> item = new HashMap<String, Object>();
                    item.put("name", name[i]);
                    item.put("words",words[i]);
                    item.put("png", png[i]);
                    items.add(item);
                }
                myadapter.notifyDataSetChanged();
            }
        });
        return view;
    }
}




